package com.southwind.controller;


import com.southwind.entity.Fruit;
import com.southwind.service.FruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yinxiaozhi
 * @since 2021-05-23
 */
@RestController
@RequestMapping("//fruit")
public class FruitController {
    
    @Autowired
    private FruitService fruitService;
    
    @GetMapping("/list")
    private List<Fruit> list(){
        return fruitService.list();
    }
    
    @GetMapping("/selectById/{id}")
//    public Fruit selectById(@PathVariable("id") Integer iddd){//OK。。。
//        return fruitService.getById(iddd);
//    }
    public Fruit selectById(@PathVariable("id") Integer id){//OK。。。
        return fruitService.getById(id);
    }
    
    @DeleteMapping("/deleteById/{idds}")
    public String deleteById(@PathVariable("idds") Integer iddsaa){//OK。。。
        boolean b = fruitService.removeById(iddsaa);
        if(b){
            return "删除成功，成功。";
        }
        return "删除失败了。";
    }
    
    @PostMapping("/savefruit")
    public String savefruit(@RequestBody Fruit fruit){
        boolean save = fruitService.save(fruit);
        if(save){
            return "添加成功，成功。。";
        }
        return "添加失败了。";
    }
    
    @PutMapping("/updateById/{id}")
    public String updateById(@RequestBody Fruit fruit){
        boolean b = fruitService.updateById(fruit);
        if(b){
            return "修改成功，成功。";
        }
        return "修改失败了。";
    }
    
}

